import { Helper } from "@/core/helper/helper.service";
import { DialogProps, ElDialog } from "element-plus";
import { Component, ComputedOptions, MethodOptions } from "vue";
import { Base, PopOption } from "./base";
export type TDialogOption = PopOption<DialogProps>;
export class Dialog extends Base<DialogProps> {
  protected getPop(): Component<any, any, any, ComputedOptions, MethodOptions> {
    return ElDialog;
  }
  constructor(option: TDialogOption, stc?: boolean) {
    super(option, stc);
  }

  protected closePop(destory: boolean): void {
    if (this.comp?.component) {
      if (this.comp?.component?.proxy) {
        this.comp.component.exposed.visible.value = false;
      }
    }

    if (destory || this.noStc) {
      setTimeout(() => {
        this.comp?.el?.parentElement.remove();
        Helper.staticDialog = null;
      }, 1000);
    }
  }

  open() {
    if (this.comp?.component?.exposed) {
      this.comp.component.exposed.visible.value = true;
      if (this.openSub.observed) {
        this.openSub.next("");
      }
    }
  }
}
